﻿using System;
using System.IO;
using System.Threading;
using GeneralDFS.Common.Logger;
using GeneralDFS.Interface.Logger;
using log4net.Config;

public class LogUtil
{
    private static ILogger _logger;

    public static void Setup()
    {
        string log4NetConfig = "log4net.config";
        if (!Path.IsPathRooted(log4NetConfig))
            log4NetConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, log4NetConfig);

        XmlConfigurator.Configure(new FileInfo(log4NetConfig));
        //_logger = new Log4NetLogger();
        _logger = new ConsoleLogger();
    }

    public static void Setup(ILogger logger)
    {
        _logger = logger;
    }

    public static ILogger GetRootLogger()
    {
        return _logger;
    }

    public static void LogError(Exception e)
    {
        if (_logger != null)
            _logger.LogError(e);
    }

    public static void LogError(string title, Exception e)
    {
        if (_logger != null)
            _logger.LogError(title, e);
    }

    public static void LogError(string message)
    {
        if (_logger != null)
            _logger.LogError(message);
    }

    public static void LogDebug(string message)
    {
        if (_logger != null)
            _logger.LogDebug(message);
    }

    public static void LogDebug(string format, params object[] args)
    {
        if (_logger != null)
            _logger.LogDebug(format,args);
    }
    public static void LogInfo(string message)
    {
        if (_logger != null)
            _logger.LogInfo(message);
    }

    public static void LogInfo(string format, params object[] args)
    {
        if (_logger != null)
            _logger.LogInfo(format,args);
    }

    public static void LogPerf(string message)
    {
        if (_logger != null)
            _logger.LogPerf(message);
    }
}